import { Injectable } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { Observable, Subject } from 'rxjs'
import { NzModalService, NzMessageService } from 'ng-zorro-antd'

import { I18NService } from '@core'

@Injectable({
  providedIn: 'root',
})
export class ModalService {
  private defaultTitle = ''

  constructor(
    private modal: NzModalService,
    private route: ActivatedRoute,
    private router: Router,
    private msg: NzMessageService,
    private i18n: I18NService,
  ) {
    this.defaultTitle = i18n.fanyi('GENERAL.NOTIFICATION.WARNING')
  }

  public warm(content: string, title: string = this.defaultTitle): Observable<boolean> {
    const operate = new Subject<boolean>()
    this.modal.confirm({
      nzTitle: title,
      nzContent: content,
      nzOnOk: () => operate.next(true)
    })
    return operate
  }

  public delete(content: string, title: string = this.defaultTitle): Observable<boolean> {
    const operate = new Subject<boolean>()
    this.modal.confirm({
      nzTitle: title,
      nzContent: content,
      nzOnOk: () => operate.next(true)
    })
    return operate
  }

  public freezeAndUnFreeze(content: string, title: string = this.defaultTitle): Observable<boolean> {
    const operate = new Subject<boolean>()
    this.modal.confirm({
      nzTitle: `<i>${title}<i>`,
      nzContent: `<b>${content}</b>`,
      nzOnOk: () => operate.next(true),
      nzOnCancel: () => operate.next(false),
    })
    return operate
  }
}
